
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> ##########################################################################################################
> #Replication Files for Housing Discrimination and the Toxics Exposure Gap in the United States: 
> #Evidence from the Rental Market  by Peter Christensen, Ignacio Sarmiento-Barbieri and Christopher Timmins
> ##########################################################################################################
> 
> #Clean the workspace
> rm(list=ls())
> cat("\014")
> local({r <- getOption("repos"); r["CRAN"] <- "http://cran.r-project.org"; options(repos=r)}) #set repo
> 
> 
> #Load Packages
> pkg<-c("dplyr","ggplot2","ggthemes")
> lapply(pkg, require, character.only=T)
Loading required package: dplyr

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

Loading required package: ggplot2
Loading required package: ggthemes
[[1]]
[1] TRUE

[[2]]
[1] TRUE

[[3]]
[1] TRUE

> rm(pkg)
> 
> 
> # Load matched inquiries data ---------------------------------------------
> matchedinquiries<-haven::read_dta("../stores/toxic_discrimination_data.dta")
> 
> 
> matchedinquiries$ToxQ<-NA
> matchedinquiries$ToxQ[matchedinquiries$quartileZIP_property==2]<-"0-25"
> matchedinquiries$ToxQ[matchedinquiries$quartileZIP_property==3]<-"25-75"
> matchedinquiries$ToxQ[matchedinquiries$quartileZIP_property==4]<-"75-100"
> 
> matchedinquiries<-matchedinquiries %>% distinct(Address,Zip_Code,.keep_all = TRUE)
> dta<-matchedinquiries[,c("dist","ToxQ","Zip_Code","toxconc")]
> 
> dta$ToxQ<-factor(dta$ToxQ, levels=c("75-100","25-75","0-25"))
> name_output<-"distance_concentration"
> ht<-4
> wd<-6
> #table(dta$Zip_Code)
> 
> colors <- tibble::deframe(ggthemes::ggthemes_data[["fivethirtyeight"]])
> base_size = 4
> base_family = "sans"
> require(grid)
Loading required package: grid
> 
> p<-ggplot(dta,aes(x=dist)) +
+   geom_histogram( colour="black", fill=colors["Medium Gray"], binwidth = .3) + #
+   theme_bw() +
+   theme_fivethirtyeight() + scale_color_fivethirtyeight("cyl") +
+   facet_grid(ToxQ~.) +
+   geom_vline(aes(xintercept=1), colour="royalblue4", linetype="twodash") +
+   scale_x_continuous("Distance to TRI plant",breaks=c(0,1,2,3,4,5,6),limits=c(-0.25,6)) +
+   #coord_cartesian(xlim = c(-0.25,6), clip = 'on') +
+   xlab("Distance to TRI facility (miles)") +
+   ylab("Number of Listings") +
+   # annotate("text",x= 8, y = 200, 
+   #          label = ,  
+   #          size= base_size-1, family=base_family, color=colors["Dark Gray"], angle=360) +
+   theme(legend.title= element_blank() ,
+         legend.position="none",
+         legend.justification=c(1,1),
+         legend.direction="vertical",
+         legend.box="horizontal",
+         legend.box.just = c("top"),
+         legend.background = element_rect(fill='transparent'),
+         axis.text.x =element_text( angle=0),
+         rect = element_rect(colour = "transparent", fill = "white"),
+         axis.title = element_text(), plot.margin = unit(c(2,2,1,1), "lines"))
> 
> 
> p
Warning messages:
1: Removed 3 rows containing non-finite values (stat_bin). 
2: Removed 6 rows containing missing values (geom_bar). 
> grid.text(unit(0.98,"npc"),gp=gpar(fontsize=11,fontfamily=base_family),0.5,label = "Percentile of Within-Zip Toxic Concentration", rot = 270) # right
> ggsave("../views/figA4.png", width=10, height=5)
Warning messages:
1: Removed 3 rows containing non-finite values (stat_bin). 
2: Removed 6 rows containing missing values (geom_bar). 
> #has to be saved manually with export, and parameters width=1000, height=410 in order for the grid.text to appear
> 
> 
> proc.time()
   user  system elapsed 
  1.276   0.139   1.449 
